package com.dawn.utils;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class CalendarEditor extends PropertyEditorSupport {

	static private final String format = "yyyy-MM-dd";

	SimpleDateFormat dateFormat = new SimpleDateFormat(format);
	
	public  CalendarEditor(String thisfomart){
		super();
		
		dateFormat = new SimpleDateFormat(thisfomart);
	}
	
	public  CalendarEditor(){
		super();
	}

	public void setAsText(String value) {
		Calendar cal = Calendar.getInstance();
		try {
			java.util.Date date = dateFormat.parse(value);
			cal.setTime(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		setValue(cal);
	}

	public String getAsText() {
		Calendar cal = (Calendar) this.getValue();
		return dateFormat.format(cal.getTime());
	}

}
